import requests
import json
q = "必须实现"
cookies = {
    'BIDUPSID': 'E53ECC6A6B63A21497AD16751AF801ED',
    'PSTM': '1678155848',
    'BAIDUID': 'E53ECC6A6B63A214DD1A0672D0BE832F:FG=1',
    'APPGUIDE_10_0_2': '1',
    'REALTIME_TRANS_SWITCH': '1',
    'FANYI_WORD_SWITCH': '1',
    'HISTORY_SWITCH': '1',
    'SOUND_SPD_SWITCH': '1',
    'SOUND_PREFER_SWITCH': '1',
    'Hm_lvt_afd111fa62852d1f37001d1f980b6800': '1678342570',
    'newlogin': '1',
    'BDUSS': 'JMcmh6NFZEdFVoM25Sa0lWLXhiRmk3N0E0MXJjQ3pWcWRFVHlzVmtER1BoRk5rSVFBQUFBJCQAAAAAAAAAAAEAAACCXd4ed2hqeWJlYXIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI~3K2SP9ytkQl',
    'BDUSS_BFESS': 'JMcmh6NFZEdFVoM25Sa0lWLXhiRmk3N0E0MXJjQ3pWcWRFVHlzVmtER1BoRk5rSVFBQUFBJCQAAAAAAAAAAAEAAACCXd4ed2hqeWJlYXIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI~3K2SP9ytkQl',
    'BA_HECTOR': 'al0hah2l8ha421a40k01ahfj1i3sr431n',
    'ZFY': 'BXb5K7c8qGgXAsWADj7HXaoSjqltMXYqiiCz9Y4gDGA:C',
    'BAIDUID_BFESS': 'E53ECC6A6B63A214DD1A0672D0BE832F:FG=1',
    'delPer': '0',
    'PSINO': '7',
    'BDRCVFR[isAn9Hjp3jt]': 'mk3SLVN4HKm',
    'H_PS_PSSID': '38516_36551_38470_38355_38368_38468_38377_38485_37933_38529_26350_38186',
    'BDRCVFR[S4-dAuiWMmn]': 'I67x6TjHwwYf0',
    'BDORZ': 'B490B5EBF6F3CD402E515D22BCDA1598',
    '__bid_n': '1875b7e809ec9b6bcd4207',
    'FPTOKEN': 'EhCI2PstK0NknBn8cS8VhiLH3/QfJk2tUj27ddgQK05WM1UjTGtGlnjPBFu+04NTLkB9T4xbB4FLBURIvjdh1I7W2AiHoEYXR5RMy9D/bC/bwyERQpIS/vZahzUMCYBG+jidD3lZjuKrE0gmG8YkadpUlq1F++AXq2mynMqvaDugWXQivzvIo13TaEtyIT/3S/+oj4qzW00Nn8sNwlXF4CiW7CojZ28U1C79pT8MFISAJ4jZrc5EdK27XoZzx5QkVKbwYYDxUIlGpySNjJ5GfgJ7D/3I8qHJ5+lL0A9TKDDpkmQzmlI/WhsxSCZQ8EWjmONwJLdJsxPOXnqde/t9k/av3tDQ0DK9ckygC3ykCsYzXbQNjCeMhBYKMlEN9vuHGNW+unYdIklkF7QQ1cR5QA==|yIFtxdO103sBB6wUOuffjlWNjfkLXrKW9Pr39B6O4ww=|10|a75aba035b82c3d1f824666a000fadca',
    'RT': '"z=1&dm=baidu.com&si=1260b126-6e97-46e7-9f76-ba8cf77de72e&ss=lgm89q33&sl=2&tt=1v1&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=org&ul=10sm&hd=10tz"',
    'Hm_lvt_64ecd82404c51e03dc91cb9e8c025574': '1681637618,1681820435',
    'Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574': '1681820580',
    'ab_sr': '1.0.1_NzM2ZjExNjRhMzE5MmFmNGExODM0ODdkNzQ2NWMyZGVmODE1NmJkZDUyN2FlYjhlMDM3ZDBlYzdjYWVjZTczZWNiYWE5MTg4MDI0YjYyYTI5Y2QwODNlZDAwZWY5M2QzOWIxNTFhOTkxNDI4YWZiOTZlNmYwM2U0MDk2MTVlMDkwMmY5NDY0ODI5MTc1MDQ0NTNmZDI2NDkwNTk0MDFmY2NiMDhkYTA5NWMwM2Y5OWY4ODNjNWRmYjQwN2Y5YjUy',
}

headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Acs-Token': '1681820427289_1681820671318_AqAMMtcJ7y0e/cyjG+nGciX7cwIh/zEl6doBV6/ZLfQLlA/XGZzYWrGUkX6GhcH0YqY/nf66JWFQrYoLrM4xulepsk0BiFViDxOejnzvimyZN6wRHy6YfvCvFmDLi5dbYye9oUy7Sj624M4uLkt8MFf0lwQ46pFRUtLDxCiPO4UDZ4Er8pN/4moGjx1lrmp4E6z5HZHRGZdN4KOXvx0tmfvCYUF8qlUy4U3FuXkMzd2EBag4AnH9eaEar+1wmxOVzPGGLdSQ/YvQ9HF/V8ZwKy+lMeO6H9g/Ta2XapntUyKuUwRc5lkm1n7SkM3ftefouHFKA9PtQ8rO7cuBol46ffwYK0NyFjWes2XwIO4ljFDnhyQ5k8sMWavepuUum8ckyCaLakzaNxazpJJxauX59i48UOrWjLLENvxLF13z3HWWW/u8Lhv3SKrDTFYGU3U+9lMRiPCLShQmNRGh2ceGcnJalvUimHgllD7TzGQ1hZ8=',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    # 'Cookie': 'BIDUPSID=E53ECC6A6B63A21497AD16751AF801ED; PSTM=1678155848; BAIDUID=E53ECC6A6B63A214DD1A0672D0BE832F:FG=1; APPGUIDE_10_0_2=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; Hm_lvt_afd111fa62852d1f37001d1f980b6800=1678342570; newlogin=1; BDUSS=JMcmh6NFZEdFVoM25Sa0lWLXhiRmk3N0E0MXJjQ3pWcWRFVHlzVmtER1BoRk5rSVFBQUFBJCQAAAAAAAAAAAEAAACCXd4ed2hqeWJlYXIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI~3K2SP9ytkQl; BDUSS_BFESS=JMcmh6NFZEdFVoM25Sa0lWLXhiRmk3N0E0MXJjQ3pWcWRFVHlzVmtER1BoRk5rSVFBQUFBJCQAAAAAAAAAAAEAAACCXd4ed2hqeWJlYXIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI~3K2SP9ytkQl; BA_HECTOR=al0hah2l8ha421a40k01ahfj1i3sr431n; ZFY=BXb5K7c8qGgXAsWADj7HXaoSjqltMXYqiiCz9Y4gDGA:C; BAIDUID_BFESS=E53ECC6A6B63A214DD1A0672D0BE832F:FG=1; delPer=0; PSINO=7; BDRCVFR[isAn9Hjp3jt]=mk3SLVN4HKm; H_PS_PSSID=38516_36551_38470_38355_38368_38468_38377_38485_37933_38529_26350_38186; BDRCVFR[S4-dAuiWMmn]=I67x6TjHwwYf0; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; __bid_n=1875b7e809ec9b6bcd4207; FPTOKEN=EhCI2PstK0NknBn8cS8VhiLH3/QfJk2tUj27ddgQK05WM1UjTGtGlnjPBFu+04NTLkB9T4xbB4FLBURIvjdh1I7W2AiHoEYXR5RMy9D/bC/bwyERQpIS/vZahzUMCYBG+jidD3lZjuKrE0gmG8YkadpUlq1F++AXq2mynMqvaDugWXQivzvIo13TaEtyIT/3S/+oj4qzW00Nn8sNwlXF4CiW7CojZ28U1C79pT8MFISAJ4jZrc5EdK27XoZzx5QkVKbwYYDxUIlGpySNjJ5GfgJ7D/3I8qHJ5+lL0A9TKDDpkmQzmlI/WhsxSCZQ8EWjmONwJLdJsxPOXnqde/t9k/av3tDQ0DK9ckygC3ykCsYzXbQNjCeMhBYKMlEN9vuHGNW+unYdIklkF7QQ1cR5QA==|yIFtxdO103sBB6wUOuffjlWNjfkLXrKW9Pr39B6O4ww=|10|a75aba035b82c3d1f824666a000fadca; RT="z=1&dm=baidu.com&si=1260b126-6e97-46e7-9f76-ba8cf77de72e&ss=lgm89q33&sl=2&tt=1v1&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=org&ul=10sm&hd=10tz"; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1681637618,1681820435; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1681820580; ab_sr=1.0.1_NzM2ZjExNjRhMzE5MmFmNGExODM0ODdkNzQ2NWMyZGVmODE1NmJkZDUyN2FlYjhlMDM3ZDBlYzdjYWVjZTczZWNiYWE5MTg4MDI0YjYyYTI5Y2QwODNlZDAwZWY5M2QzOWIxNTFhOTkxNDI4YWZiOTZlNmYwM2U0MDk2MTVlMDkwMmY5NDY0ODI5MTc1MDQ0NTNmZDI2NDkwNTk0MDFmY2NiMDhkYTA5NWMwM2Y5OWY4ODNjNWRmYjQwN2Y5YjUy',
    'Origin': 'https://fanyi.baidu.com',
    'Referer': 'https://fanyi.baidu.com/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

params = {
    'from': 'zh',
    'to': 'en',
}

data = {
    'from': 'zh',
    'to': 'en',
    'query': q,
    'transtype': 'translang',
    'simple_means_flag': '3',
    'sign': '536323.838706',
    'token': 'faada14f84ec2b542ab31592f7e44ef7',
    'domain': 'common',
}

response = requests.post('https://fanyi.baidu.com/v2transapi', params=params, cookies=cookies, headers=headers, data=data)

# print(response.text)
text = response.text
# print(json.dumps(response.text,indent=None,ensure_ascii=False))
r = json.loads(text)
dst = r["trans_result"]["data"][0]["dst"]
src = r["trans_result"]["data"][0]["src"]
print(src)
print(dst)